package com.lxr0860.lxr0860production_test.db;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.DatabaseConfiguration;
import androidx.room.InvalidationTracker;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteOpenHelper;

import com.lxr0860.lxr0860production_test.base.App;
import com.lxr0860.lxr0860production_test.db.dao.DevInfoDao;
import com.lxr0860.lxr0860production_test.db.dao.MenuDao;
import com.lxr0860.lxr0860production_test.db.tb.DevInfo;
import com.lxr0860.lxr0860production_test.db.tb.Menu;
import com.lxr0860.lxr0860production_test.utils.Contants;


@Database(entities = {Menu.class, DevInfo.class},version = 1, exportSchema = false)
public abstract class MyRoomDatabase extends RoomDatabase {

    private static MyRoomDatabase INSTANCE;//声明单例对象，减小数据库开销
    private static final String DATABASE_NAME="lxr_7300_test";

    public static MyRoomDatabase getInstance() {
        //通过单例对象获取数据库
        if(INSTANCE==null){
            INSTANCE= Room.databaseBuilder(App.getContext(),MyRoomDatabase.class,DATABASE_NAME)
                    .build();
            Log.i(Contants.LOG_TAG,"【数据库】初始化,数据库名称："+DATABASE_NAME+"|版本："+1);
        }
        return INSTANCE;
    }


    public abstract MenuDao menuDao();

    public abstract DevInfoDao devInfoDao();

    @Override
    public void clearAllTables() {

    }

    @NonNull
    @Override
    protected InvalidationTracker createInvalidationTracker() {
        return null;
    }

    @NonNull
    @Override
    protected SupportSQLiteOpenHelper createOpenHelper(@NonNull DatabaseConfiguration databaseConfiguration) {
        return null;
    }
}
